/// describe
///
/// created by hujintao
/// created at 2021/5/17
//

import 'package:flutter/material.dart';
/// 页面导航
/// 可自定义切页效果
class NavigatorUtil {

  static void push(BuildContext context, Widget page) {
    Navigator.of(context).push(MaterialPageRoute(builder: (context) => page));
  }

  static void pushFade(BuildContext context, Widget page) {
    Navigator.of(context).push(CustomRouteFade(page));
  }

  /// 通用跳转
  static pushAll(BuildContext context,Widget widget )async {
    await Navigator.push(context, PageRouteBuilder(transitionDuration: Duration(milliseconds: 300),
        pageBuilder: (context, animation, secondaryAnimation){
          return new FadeTransition( //使用渐隐渐入过渡,
            opacity: animation,
            child:widget,
          );
        })
    );
  }
}

// 渐变效果
class CustomRouteFade extends PageRouteBuilder {
  final Widget widget;
  CustomRouteFade(this.widget)
      : super(
      transitionDuration: const Duration(milliseconds: 600),
      pageBuilder: (BuildContext context, Animation<double> animation1,
          Animation<double> animation2) {
        return widget;
      },
      transitionsBuilder: (BuildContext context,
          Animation<double> animation1,
          Animation<double> animation2,
          Widget child) {
        return FadeTransition(
          opacity: Tween(begin: 0.0, end: 2.0).animate(CurvedAnimation(
              parent: animation1, curve: Curves.fastOutSlowIn)),
          child: child,
        );
      });
}
